apt update
cd /home/guoqiang/cmake-3.22.0/
./bootstrap
make
make install
export PATH=/home/ascend/cmake-3.22.0/bin:$PATH
#export PATH=/home/guoqiang/cmake-3.22.0/bin:$PATH

python3 /home/xutianci/from_17/xutianci/get-pip.py --upgrade pip==24.0
#scp root@10.110.153.120:/home/ascend/ModelZoo-PyTorch/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/apex/apex root@10.110.153.110:/home/guoqiang/apex/

cd /home/ascend/ModelZoo-PyTorch/ACL_PyTorch/built-in/nlp/Bert_Base_Chinese_for_Pytorch
#pip3 install torch==1.8.0 pip3 install torch==1.11.0
#pip3 install torchvision==0.9.1 pip3 install torchvision==0.12.0
pip3 install transformers==4.19.2
pip3 install datasets==2.3.0
pip3 install onnx
pip3 install onnx-simplifier==0.3.10
pip3 install wikiextractor
pip3 install sklearn==0.0
pip3 install tqdm
#pip3 install scikit-learn

scp root@10.110.153.120:/home/ascend/zhwiki-latest-pages-articles.xml root@10.110.153.110:/home/ascend/
python3 WikiExtractor.py /home/ascend/zhwiki-latest-pages-articles.xml -b 100M -o extracted/wiki_zh
python3 WikicorpusTextFormatting.py --extracted_files_path extracted/wiki_zh --output_file zhwiki-latest-pages-articles.txt
python3 split_dataset.py zhwiki-latest-pages-articles.txt zhwiki-latest-pages-articles_validation.txt
#export LD_PRELOAD=/usr/local/python3.9.2/lib/python3.9/site-packages/sklearn/utils/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0:$LD_PRELOAD
#mkdir /home/huggingface/datasets -p
#export HF_DATASETS_CACHE=/home/huggingface/datasets
#ln -s /home/ascend/bert-base-chinese/ .
python3 preprocess.py ./zhwiki-latest-pages-articles_validation.txt ./bert-base-chinese ./input_data/ 256


git clone https://gitee.com/Ronnie_zheng/MagicONNX.git MagicONNX
cd /home/guoqiang/MagicONNX
pip3 install . && cd ..
source /usr/local/Ascend/ascend-toolkit/set_env.sh


pip3 install /home/ascend/aclruntime-0.0.2-cp39-cp39-linux_aarch64.whl --force-reinstall
pip3 install /home/ascend/ais_bench-0.0.2-py3-none-any.whl --force-reinstall
pip3 install numpy==1.26.4

#scp onnx 
cd /home/ascend/ModelZoo-PyTorch/ACL_PyTorch/built-in/nlp/Bert_Base_Chinese_for_Pytorch
for bs in 1 4 8 16 32 64 128 192 256
do
    echo "bs: $bs"
    if [ -f "./bert_base_chinese_bs${bs}.om" ]; then
        echo "File ./bert_base_chinese_bs${bs}.om already exists. Skipping..."
    else
        python3 -m onnxsim ./bert_base_chinese.onnx ./bert_base_chinese_bs${bs}.onnx --input-shape "input_ids:${bs},256" "attention_mask:${bs},256" "token_type_ids:${bs},256"
        python3 fix_onnx.py bert_base_chinese_bs${bs}.onnx bert_base_chinese_bs${bs}_fix.onnx
        atc --model=./bert_base_chinese_bs${bs}_fix.onnx --framework=5 --output=./bert_base_chinese_bs${bs} --input_format=ND --log=debug --soc_version=Ascend310P3 --optypelist_for_implmode="Gelu" --op_select_implmode=high_performance
        #atc --model=./bert_base_chinese_bs${bs}_fix.onnx --framework=5 --output=./bert_base_chinese_bs${bs} --input_format=ND --log=debug --soc_version=Ascend910B4 --optypelist_for_implmode="Gelu" --op_select_implmode=high_performance
    fi
    # 以bs1模型推理为例
    mkdir -p ./output_data/bs${bs}
    python3 -m ais_bench --model ./bert_base_chinese_bs${bs}.om --input ./input_data/input_ids,./input_data/attention_mask,./input_data/token_type_ids --output ./output_data/ --output_dirname bs${bs} --batchsize ${bs} --device 1
    # 以bs1模型推理为例
    # 输入参数：${result_dir} ${gt_dir} ${seq_length}
    python3 postprocess.py ./output_data/bs${bs} ./input_data/labels 256
done



#data
python3 preprocess.py \
    --src_path /home/xutianci/ImageNet/val \
    --save_path ./prep_dataset

#msit
cd /home/guoqiang/
pip install msit
msit install surgeon llm
msit install all
msit check all 

#auto-optimizer
cd msit/msit/components/debug/surgeon
python3 -m pip install wheel
python3 -m pip install .
python3 -m pip install .[simplify]

export PATH=/home/ascend/cmake-3.22.0/bin:$PATH
pip3 install tensorflow
pip3 install tf2onnx
pip3 install onnx==1.9.0
pip3 install onnxruntime==1.8.0
pip3 install numpy==1.20.0
pip3 install protobuf==3.13.0 
#anzhuang amct_onnx
cd /home/xutianci/amct/amct_onnx/
pip3 install /home/xutianci/amct/amct_onnx/amct_onnx-0.14.0-py3-none-linux_aarch64.whl
tar -zvxf amct_onnx_op.tar.gz
cd amct_onnx_op && python3 setup.py build
cd /home/xutianci/ModelZoo-PyTorch/ACL_PyTorch/built-in/cv/Resnet50_mlperf

python -m tf2onnx.convert --input resnet50_v1.pb --inputs input_tensor:0[1,3,224,224] --rename-inputs dummy_input --inputs-as-nchw dummy_input --outputs ArgMax:0 --output resnet50_tmp.onnx --opset 11
python re_domain.py resnet50_tmp.onnx resnet50.onnx
rm -rf resnet50_tmp.onnx

amct_onnx calibration  --model resnet50.onnx  --save_path ./models/resnet50_quant  --input_shape "dummy_input:-1,3,224,224"  --data_dir "./amct_bin_data/"  --data_types "float32"  --calibration_config ./quant.cfg
source /usr/local/Ascend/ascend-toolkit/set_env.sh 

for bs in 1 32 64 128 256
do
atc --model=models/resnet50_quant_deploy_model.onnx \
--framework=5 \
--output=resnet50_bs${bs} \
--input_format=NCHW \
--input_shape="dummy_input:${bs},3,224,224" \
--log=error \
--insert_op_conf=./aipp_resnet50.conf \
--enable_small_channel=1 \
--soc_version=Ascend910B4

python3 -m ais_bench --model ./resnet50_bs${bs}.om --input ./prep_dataset/ --output ./ --output_dirname result
cp /home/xutianci/ImageNet/val_label.txt .
python3 accuracy.py ./result ./val_label.txt ./result${bs}.json

done




#yolov5
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export LD_PRELOAD=/usr/local/python3.9.2/lib/python3.9/site-packages/torch.libs/libgomp-98df74fd.so.1.0.0
pip3 install torch==2.6.0 torchvision==0.21.0
pip3 install pycocotools
pip3 install torchvision==0.21.0
pip3 install seaborn

bash pth2onnx.sh --tag 6.1 --model yolov5m --nms_mode nms_script  # nms_script
for bs in 1 32 64 128 256
do
bash onnx2om.sh --tag 6.1 --model yolov5m --nms_mode nms_script --bs ${bs} --soc Ascend310P3  # nms_script
#python3 om_val.py --tag 6.1 --model=yolov5m_bs${bs}.om --nms_mode nms_script --batch_size=${bs}  # nms_script
python3 -m ais_bench --model=yolov5m_bs${bs}.om --loop=1000 --batchsize=${bs}  # nms_script
done